<?php

namespace app\api\model;

use think\Model;

class Area extends Model
{
    public static function getLevelTwoList()
    {
        return self::where('level', 2)
            ->order('id desc')
            ->field('adcode,shortname,name,lng,lat,first,pinyin')
            ->select()
            ->toArray();
    }

    public static function getRecentlyArea($lng, $lat)
    {
        return self::where('level', 2)->field("adcode,shortname,name,pinyin,lng,lat,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(({$lat}*PI()/180-lat*PI()/180)/2),2)+COS({$lat}*PI()/180)*COS(lat*PI()/180)*POW(SIN(({$lng}*PI()/180-lng*PI()/180)/2),2)))*1000) AS distance_miles")
            ->order('distance_miles asc')
            ->find();
    }
}